package com.liang.controller;


import com.liang.common.lang.Result;
import com.liang.service.CActiveService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 李昂
 * @since 2020-11-30
 */
@RestController
@RequestMapping("/active")
@AllArgsConstructor
public class CActiveController {

    private CActiveService activeService;


    //获取活动列表
    @GetMapping
    public Result getActives() {
        return Result.succ(activeService.getActives());
    }

    @GetMapping("/count")
    public Result takeActiveCount(@RequestParam("id") String id) {
        return Result.succ(activeService.takeActiveCount(id));
    }

    //获取活动详情页面
    @GetMapping("/{id}")
    public Result getDetail(@PathVariable("id") int id) {
        return Result.succ(activeService.getDetail(id));
    }

    //报名参加活动
    @PostMapping("/{aid}")
    public Result takeInActive(@PathVariable("aid") int aid, @RequestParam("id") String id) {
        if (activeService.takeInActive(aid, id)) {
            return Result.succ();
        } else {
            return Result.fail();
        }
    }

    //取消报名参加活动
    @DeleteMapping("/{aid}")
    public Result CancelActive(@PathVariable("aid") int aid, @RequestParam("id") String id) {
        if (activeService.CancelActive(id, aid)) {
            return Result.succ();
        } else {
            return Result.fail();
        }
    }


}
